//
//  GTQHistoryCell.m
//  GTQCitySelector
//
//  Created by 光头强 on 16/7/22.
//  Copyright © 2016年 Ls. All rights reserved.
//

#import "GTQHistoryCell.h"

@implementation GTQHistoryCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setHistroys:(NSArray *)cityArr {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGFloat leftMargin = 15;        //左边的缝隙
    CGFloat topMargin = 20;        //顶部的缝隙
    
    CGFloat margin = 10;            //Label之间的缝隙
    CGFloat width = ((ScreenWidth-10)-2*leftMargin-2*margin)/3;
    CGFloat height = 44;
    
    int totalloc = 3;  //总共3列
    
    for (int i=0; i<cityArr.count; i++) {
        
        int loc = i%totalloc;  //列号
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(leftMargin+(width+margin)*loc, topMargin, width, height)];
        
        label.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)];
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        [label addGestureRecognizer:tap];
        
        label.text = cityArr[i];
        label.textAlignment = NSTextAlignmentCenter;
        
        label.backgroundColor =RGBColor(245, 245, 245);
        
        [self.contentView addSubview:label];
    }
}

#pragma mark - 点击Label
- (void)labelTap:(UITapGestureRecognizer *)tap
{
    if ([tap.view isKindOfClass:[UILabel class]]) {
        
        UILabel *label = (UILabel *)tap.view;
        
        if ([_delegate respondsToSelector:@selector(HistoryCell:didClickWithLabelText:)]) {
            [_delegate HistoryCell:self didClickWithLabelText:label.text];
        }
        
        NSLog(@"%@",label.text);
    }
}

@end
